#include <gst/gst.h>
#include <stdlib.h>

static void option(int argc, char *argv[])
{
    gboolean silent = FALSE;
    gchar *savefile = NULL;
    GOptionContext *ctx = NULL;
    GError *err = NULL;
    GOptionEntry entries[] = {
      { "silent", 's', 0, G_OPTION_ARG_NONE, &silent, "do not output status information", NULL},
      { "output", 'o', 0, G_OPTION_ARG_STRING, &savefile, "save xml representation of pepeline to FILE and exit", "FILE"},
      { NULL }
    };

    ctx = g_option_context_new(" - Your application");

    g_option_context_add_main_entries(ctx, entries, NULL);
    g_option_context_add_group(ctx, gst_init_get_option_group());
    if (! g_option_context_parse(ctx, &argc, &argv, &err)) {
        g_print("Failed to initialize: %s\n", err->message);
        g_clear_error(&err);
        g_option_context_free(ctx);
        return;
    }
    g_option_context_free(ctx);
}

static void version()
{
    const gchar *nano_str = NULL;
    guint major, minor, micro, nano;

    gst_version(&major, &minor, &micro, &nano);

    if (nano == 1) {
        nano_str = "(CVS)";
    } else if (nano == 2) {
        nano_str = "(Prerelease)";
    } else {
        nano_str = "";
    }

    g_print("This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str);
//    g_print("This program is linked against GStreamer %d.%d.%d\n", GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO);

}

static void creat_element()
{
//    GstElementFactory *factory = NULL;
    GstElement *element = NULL;
    gchar *name = NULL;

    element = gst_element_factory_make("fakesrc", "source");

//    factory = gst_element_factory_find("fakesrc");
//    if (!factory) {
//        g_print("Failed to create factory of type 'fakesrc'\n");
//        exit(-1);
//    }
//    element = gst_element_factory_create(factory, "source");

    if (!element) {
        g_print("Failed to create element of type 'fakesrc'\n");
        exit(-1);
    }

    /* get name */
    g_object_get(G_OBJECT(element), "name", &name, NULL);
    g_print("The name of the element is '%s'.\n", name);
    g_free(name);

    gst_object_unref(element);
}

int main(int argc, char *argv[])
{  
	/* Initialize GStreamer */  
	gst_init (&argc, &argv);  
    option(argc, argv);
    version();
    creat_element();

    return 0;
}
